import { _decorator } from 'cc';
import { BaseUI } from '../../framework/base/BaseUI';
import { ADType, BaseEventName } from '../../framework/config/Appcfg';
import { SDKMgr } from '../../framework/manager/SDKMgr';
import { UIMgr } from '../../framework/manager/UIMgr';
import { UIID } from '../config/Config';
import { GameDef } from '../gameLogic/GameDef';
const { ccclass, property } = _decorator;

@ccclass('UIResurrect')
export class UIResurrect extends BaseUI {
    tipText: any = null
    isWin: boolean = false
    gameType: number = 0
    public init(param1?: any, param2?: any, param3?: any, param4?: any, param5?: any): void {
        this.tipText = param1
        this.isWin = param2
        this.gameType = param3
    }

    start() {
        //视频复活
        this.findChilds("btn_lv").on("click", this.onViodePlay, this)
        //回到首页
        this.findChilds("closeBtn").on("click", this.onBackHome, this)
    }
    onCloseBtn() {
        this.onToCloseView()
    }
    onViodePlay() {
        SDKMgr.getInstance().playVideo((isComp) => {
            if (isComp) {
                this.onToCloseView();
                this.sendEvent(BaseEventName.Video_Revival);
                console.log("视频复活");
                GameDef.instance.reportInfo.ad_video_times += 1;
                GameDef.instance.reportInfo.revivetime += 1;
            };
            SDKMgr.getInstance().reportEvent("showad", {
                "adtype": "video",
                "opportunity": ADType.REPLAYER,
                "passpercent": GameDef.instance.reportInfo.levelPorgress,
                "video_complete": isComp + '',
                "is_stage": "true",
                "stage": `第${GameDef.instance.curLevel}关`,
                "level_type": "主线"
            });
        }, ADType.REPLAYER)
    }
    onBackHome() {
        this.onToCloseView()
        UIMgr.getInstance().openUI(UIID.UIOver, UIID.Default, this.tipText, this.isWin, this.gameType)
    }
    onToCloseView() {
        this.closeUI();
        // this.report();
    }
    report() {
        // SDKMgr.getInstance().reportEvent("exitstage", {
        //     "level_type": "主线",
        //     "stage": GameDef.instance.gameTypeName[GameDef.instance.reportInfo.gameType],
        //     "passstage": 0,
        //     "exit_info": "中途退出",
        //     "revivetime": GameDef.instance.reportInfo.revivetime,
        //     "tip": GameDef.instance.reportInfo.tip,
        //     "refresh": GameDef.instance.reportInfo.refresh,
        //     "knock": GameDef.instance.reportInfo.knock,
        //     "passpercent": GameDef.instance.reportInfo.levelPorgress,
        //     "points": GameDef.instance.currLevelTotalPoints,
        //     "ad_video_times": GameDef.instance.reportInfo.ad_video_times,
        //     "max_combo": GameDef.instance.comboCount,
        // })
    }
}


